<?php
/*
 * @Author: your name
 * @Date: 2020-05-22 10:17:08
 * @LastEditTime: 2020-05-26 10:16:22
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /v3/application/adminapiv3/service/attackLogManage/fileLogManage/ScreeningLogService.php
 */ 
namespace app\adminapiv3\service\attackLogManage\fileLogManage;

use app\adminapiv3\service\attackLogManage\fileLogManage\FileLogService;

class ScreeningLogService extends FileLogService
{
    /**
     * @name: 列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 10:18:08
     */
    function list ($input)
    {
        $input['source'] = self::SOURCE_FILE_SCANNING;
        $input['hsot_id']= $this->belongedHost();
        $return = $this->DbList($input);
        $return['data'] = $this->handleData($return['data']);

        return $return;
    }

    /**
     * @name: 数据库列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 10:27:50
     */
    function DbList ($filterData)
    {

        $server = db('file_attack')->alias('fa')
            ->join('host h', 'fa.host_id = h.id')
            ->field('fa.*, h.name');

        !isset($filterData['source']) || empty($filterData['source']) ? : $server->where('fa.source', $filterData['source']);
        !isset($filterData['attack_dest']) || empty($filterData['attack_dest']) ? : $server->whereLike('h.name', '%'. $filterData['attack_dest'] . '%');
        !isset($filterData['path']) || empty($filterData['path']) ? : $server->whereLike('fa.path', '%'. $filterData['path'] . '%');

        if (isset($filterData['atime']) && !empty($filterData['atime']))
        {
            $stime = strtotime($filterData['atime']);
            $etime = $stime + 86400;
            $server->whereBetween('atime', [$stime,$etime]);
        }

        !isset($filterData['level']) || !is_numeric($filterData['level']) ? : $server->where('level', $filterData['level']);

        if (isset($filterData['handle']) && is_numeric($filterData['handle'])) {
            $server->where('handle', $filterData['handle']);
        }

        $return = $server->order('fa.id', 'desc')->paginate($filterData['limit'])->toArray();

        return $return;
    }

}